<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class iJoomla_SurveysViewPrevsurvey extends JView {
	
	function display($tpl = null){
		JToolBarHelper::title(JText::_('COM_SURVEYS_SURVEY'));
		parent::display($tpl);				
	}
	
	function SurveyDetails($survey_id){
		$model = $this->getModel('prevsurvey');
		$result = $model->getSurveyDetails($survey_id);
		return $result;
	}
	
	function Params(){
		$model = $this->getModel('prevsurvey');
		$result = $model->getParams();
		return $result;
	}	
	
	function allPages($survey_id){
		$model = $this->getModel('prevsurvey');
		$result = $model->getAllPages($survey_id);
		return $result;
	}
	
	function pageDetails($page_id){
		$model = $this->getModel('prevsurvey');
		$result = $model->getPageDetails($page_id);
		return $result;
	}
	
	function surveyContent($survey_id, $current_page_id, $params, $session_id){
		include_once(JPATH_ROOT.DS."components".DS."com_surveys".DS."helpers".DS."questions.php");
		$question_list = new QuestionsList();		
		$result = $question_list->getQuestionsList($survey_id, $current_page_id, $params, "", $session_id);
		return $result;
	}
	
	function getPrevNextPage($survey_id, $current_page_id, $page_order){
		$model = $this->getModel('prevsurvey');
		$pages = $model->getPrevNextPage($survey_id, $current_page_id, $page_order);
		return $pages; 
	}
	
	function lastPage($survey_id, $params, $survey_id_alias){
		$model = $this->getModel('prevsurvey');
		$details = $model->getDetails($survey_id);
		$return = "";
				
		if($details["0"]["form_target"]=="0"){		
			$return .= '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
			$return .= 		'<tr>';
			$return .= 			'<td class="'.$params->survey_name.'">'.$details["0"]["title"].'</td>';
			$return .= 		'</tr>';
			$return .= '</table>';
			
			$return .= '<table cellspacing="0" cellpadding="0" align="center" width="100%" class="maintable">';
			$return .= 		'<tr>';
			$return .= 			'<td class="">'.$details["0"]["end_page_title"].'</td>';
			$return .= 		'</tr>';
			$return .= 		'<tr>';
			$return .= 			'<td align="left" width="100%">';
			$return .= 				$details["0"]["end_page_description"];
			$return .= 			'</td>';
			$return .= 		'</tr>';			
			$return .= '</table>';
		}
		else{
			$return = "<script language='javascript1.2' >alert('".$details["0"]["redirection_msg"]."'); window.location='".JRoute::_($details["0"]["redirection_url"])."'</script>";
		}	
		return $return;
	}
	
	function saveFields(){
		$model = $this->getModel('prevsurvey');
		$model->save();
	}
}

?>